<template>
  <!-- 主播管理 -->
  <div class="artist-data">
    <el-card
      class="table-card header_boder_bottom artist_tabel_box"
      shadow="never"
    >
      <!-- 列表搜索 -->
      <div v-if="showType == 'pc'" class="sreach-box">
        <Add ref="addDrama" style="height: 32px" @close="closeAdd"></Add>
        <div class="sreach-right-box">
          <el-row :gutter="20">
            <el-col :span="16" class="marb">
              <el-input
                v-model="searchText"
                placeholder="请输入内容"
                style="width: 300px"
                class="input-with-select"
                clearable
                @clear="onSearch"
              >
                <el-select
                  slot="prepend"
                  v-model="searchType"
                  style="width: 100px"
                  placeholder="请选择"
                  @change="changeSearch"
                >
                  <el-option label="公司名称" value="company_name"></el-option>
                  <el-option label="产品名称" value="product_name"></el-option>
                  <el-option label="产品尺寸" value="product_size"></el-option>
                </el-select>
                <el-button
                  slot="append"
                  icon="el-icon-search"
                  @click="onSearch"
                ></el-button>
              </el-input>
            </el-col>
            <el-col :span="8" class="marb">
              <el-button
                type="primary"
                style="margin-right: 15px"
                ghost
                @click="emptsearch"
              >
                重置
              </el-button>
              <el-button type="primary" ghost @click="onSearch">搜索</el-button>
            </el-col>
          </el-row>
        </div>
      </div>

      <el-row v-if="showType == 'mobile'" :gutter="20">
        <el-col :span="16">
          <el-input
            v-model="searchText"
            placeholder="请输入内容"
            style="width: 300px"
            class="input-with-select"
            clearable
            @clear="onSearch"
          >
            <el-select
              slot="prepend"
              v-model="searchType"
              style="width: 100px"
              placeholder="请选择"
              @change="changeSearch"
            >
              <el-option label="公司名称" value="company_name"></el-option>
              <el-option label="产品名称" value="product_name"></el-option>
              <el-option label="产品尺寸" value="product_size"></el-option>
            </el-select>
            <el-button
              slot="append"
              icon="el-icon-search"
              @click="onSearch"
            ></el-button>
          </el-input>
        </el-col>
      </el-row>

      <div
        v-if="showType == 'mobile'"
        class="sreach-box"
        style="margin-top: 10px"
      >
        <Add ref="addDrama" style="height: 32px" @close="closeAdd"></Add>
        <div class="sreach-right-box" style="margin-left: 20px">
          <el-row :gutter="20">
            <el-col :span="24">
              <el-button
                type="primary"
                style="margin-right: 15px"
                ghost
                @click="emptsearch"
              >
                重置
              </el-button>
              <el-button type="primary" ghost @click="onSearch">搜索</el-button>
            </el-col>
          </el-row>
        </div>
      </div>

      <div v-if="data" v-loading="tableLoading" class="tab_box">
        <XgmTable
          ref="artistTable"
          :columns.sync="columnsShow"
          :data="data"
          :is-set-up="false"
          @selectionChange="selectionChange"
          @sortChange="sortChange"
        >
          <!-- 高亮表头 -->
          <template
            v-for="(prop, i) in redTable"
            :slot="`header-${prop}`"
            slot-scope="{ label }"
          >
            <span :key="i">
              <span style="color: red">{{ label }}</span>
            </span>
          </template>
          <template slot="width" slot-scope="{ scope }">
            <span>{{ scope.row.width }}*{{ scope.row.height }}</span>
          </template>
          <template slot="workmanship" slot-scope="{ scope }">
            <span v-if="scope.row.covering">
              {{
                ['亮膜', '哑膜', '镭射膜', '转移', '上油'][
                  scope.row.covering - 1
                ]
              }}
            </span>
            <span v-if="scope.row.emboss">击凸</span>
            <span v-if="scope.row.nuv">逆向UV</span>
            <span v-if="scope.row.bronzing">烫金</span>
            <span v-if="scope.row.freight">运费</span>
            <span v-if="scope.row.uv">UV</span>
            <span v-if="scope.row.coding">打码</span>
            <span v-if="scope.row.else" style="margin-left: 3px">
              {{ scope.row.elseName }}
            </span>
          </template>

          <template slot="edit" slot-scope="{ scope }">
            <div class="edit-box">
              <el-button
                type="primary"
                class="bg-6BD9BA"
                @click="handle_look(scope.row, 'edit')"
              >
                编辑
              </el-button>
              <el-button
                type="danger"
                class="bg-6BD9BA"
                @click="handle_look(scope.row, 'delete')"
              >
                删除
              </el-button>
            </div>
          </template>
        </XgmTable>
        <div class="page-footer">
          <el-pagination
            background
            layout="prev, pager, next"
            :current-page="pagination.page"
            :page-size="pagination.pageSize"
            :page-sizes="pagination.pageSizeS"
            :total="pagination.total"
            @current-change="
              (e) => {
                pagination.page = e
                getAnchorList()
              }
            "
          ></el-pagination>
        </div>
      </div>
    </el-card>
  </div>
</template>
<script>
  let columns = [
    {
      label: '时间',
      prop: 'creattime',
      width: '150',
      showOverflowTooltip: true,
    },
    {
      label: '公司名称',
      prop: 'company_name',
      width: '150',
      showOverflowTooltip: true,
    },
    {
      label: '产品名称',
      prop: 'product_name',
      width: '150',
      showOverflowTooltip: true,
    },
    {
      label: '材质',
      width: '100',
      prop: 'material',
      showOverflowTooltip: true,
    },
    {
      label: '克重（千克）',
      prop: 'weight',
      width: '150',
      showOverflowTooltip: true,
    },
    {
      label: '开料（米）',
      prop: 'width',
      width: '120',
      showOverflowTooltip: true,
    },
    {
      label: '拼板（个）',
      prop: 'count',
      width: '120',
      showOverflowTooltip: true,
    },
    {
      label: '工艺',
      width: '200',
      prop: 'workmanship',
      showOverflowTooltip: true,
    },
    {
      label: '尺寸',
      prop: 'product_size',
      width: '100',
      showOverflowTooltip: true,
    },
    {
      label: '报价（元）',
      prop: 'allNum',
      width: '100',
      showOverflowTooltip: true,
    },
    {
      label: '订单数量（万）',
      prop: 'orderNum',
      width: '100',
      showOverflowTooltip: true,
    },
    {
      label: '报价执行',
      prop: 'name',
      width: '120',
      showOverflowTooltip: true,
    },
    {
      label: '纸价（千元/吨）',
      prop: 'price',
      width: '120',
      showOverflowTooltip: true,
    },
    {
      label: '利润',
      prop: 'profit',
      width: '100',
      showOverflowTooltip: true,
    },
    {
      label: '报价人',
      prop: 'allName',
      width: '100',
      showOverflowTooltip: true,
    },
    {
      label: '备注',
      prop: 'remarks',
      width: '200',
      showOverflowTooltip: true,
    },
    {
      label: '操作',
      prop: 'edit',
      fixed: 'right',
      width: '140',
    },
  ]

  let elseColumns = [
    {
      label: '时间',
      prop: 'creattime',
      width: '150',
      showOverflowTooltip: true,
    },
    {
      label: '公司名称',
      prop: 'company_name',
      width: '150',
      showOverflowTooltip: true,
    },
    {
      label: '产品名称',
      prop: 'product_name',
      width: '150',
      showOverflowTooltip: true,
    },
    {
      label: '材质',
      width: '100',
      prop: 'material',
      showOverflowTooltip: true,
    },
    {
      label: '克重（千克）',
      prop: 'weight',
      width: '150',
      showOverflowTooltip: true,
    },
    {
      label: '开料（米）',
      prop: 'width',
      width: '120',
      showOverflowTooltip: true,
    },
    {
      label: '拼板（个）',
      prop: 'count',
      width: '120',
      showOverflowTooltip: true,
    },
    {
      label: '工艺',
      width: '200',
      prop: 'workmanship',
      showOverflowTooltip: true,
    },
    {
      label: '尺寸',
      prop: 'product_size',
      width: '100',
      showOverflowTooltip: true,
    },
    {
      label: '报价（元）',
      prop: 'allNum',
      width: '100',
      showOverflowTooltip: true,
    },
    {
      label: '订单数量（万）',
      prop: 'orderNum',
      width: '100',
      showOverflowTooltip: true,
    },
    {
      label: '报价执行',
      prop: 'name',
      width: '120',
      showOverflowTooltip: true,
    },
    {
      label: '报价人',
      prop: 'allName',
      width: '100',
      showOverflowTooltip: true,
    },
    {
      label: '备注',
      prop: 'remarks',
      width: '200',
      showOverflowTooltip: true,
    },
    {
      label: '操作',
      prop: 'edit',
      fixed: 'right',
      width: '140',
    },
  ]
  import { guildList, deleteGuild } from '@/api/vab/guild.js'
  import XgmTable from '@/components/XgmTable'
  import Add from './components/add.vue'
  export default {
    name: 'RecommendList',
    components: { XgmTable, Add },
    props: {},
    data () {
      return {
        data: [],
        columns,
        elseColumns,
        redTable: [],
        pagination: {
          total: 0,
          page: 1,
          pageSize: 10, //每页中显示10条数据
          pageSizeS: [10, 20, 40],
          showTotal: (total) => `共有 ${total} 条数据`,
        },
        search_queryParam: {
          company_name: '',
          product_name: '',
          product_size: '',
        },
        sort: {
          order_type: 'desc', // 'desc ,
          order_key: 'update_time',
        },
        tableLoading: false,
        class_list: {
          8: [],
          9: [],
        },
        searchText: '',
        searchType: 'company_name',
        useriInfo: '',
        showType: 'pc',
      }
    },
    computed: {
      columnsShow: {
        get () {
          if (this.useriInfo.is_admin) {
            return this.columns
          } else {
            return this.elseColumns
          }
        },
        set (val) {
          this.exportColumns = val.filter((item) => item.prop != 'edit')
        },
      },
      orderBy () {
        return {
          [this.sort.order_key]: this.sort.order_type,
        }
      },
      // 选中的数据id
      ids () {
        return this.seltTableData.map((item) => item.id)
      },
    },
    watch: {},
    async created () {
      let datas = localStorage.getItem('userInfo')
      datas = JSON.parse(datas)
      this.useriInfo = datas
      // 列表
      this.getAnchorList()

      if (/Mobi|Android|iPhone/i.test(navigator.userAgent)) {
        // 当前设备是移动设备
        this.showType = 'mobile'
      } else {
        this.showType = 'pc'
      }
    },
    methods: {
      changeSearch (e) {
        this.searchText = ''
        Object.assign(
          this.search_queryParam,
          this.$options.data().search_queryParam
        )
      },

      isJSON (str) {
        try {
          JSON.parse(str)
        } catch (e) {
          // 转换出错，抛出异常
          return false
        }
        return true
      },

      async getAnchorList () {
        this.tableLoading = true
        let params = {
          page: this.pagination.page,
          pageSize: this.pagination.pageSize,
          ...this.search_queryParam,
          username: this.useriInfo.username,
        }
        let data = await guildList(params)
        if (data.code == 200) {
          this.pagination = Object.assign(this.pagination, {
            total: data.totalCount,
          })
          let list = data.products
          let newList = list.map((item) => {
            if (item.content && this.isJSON(item.content)) {
              let content = JSON.parse(item.content)
              item.material =
                content.basicForm.material == 'baiban' ? '白板' : '白卡'
              item.weight = content.basicForm.weight
              item.width = content.basicForm.width
              item.height = content.basicForm.height
              item.count = content.basicForm.count
              item.price = content.basicForm.price
              item.profit = content.basicForm.profit
              item.orderNum = content.basicForm.orderNum
              item.workmanship = ''
              item.allNum = content.allNum
              item.allName = content.allName

              item.covering = content.elseForm.covering
              item.emboss = content.elseForm.emboss
              item.nuv = content.elseForm.nuv
              item.bronzing = content.elseForm.bronzing
              item.freight = content.elseForm.freight
              item.uv = content.elseForm.uv
              item.coding = content.elseForm.coding
              item.else = content.elseForm.else
              item.elseName = content.elseForm.elseName
            }
            return item
          })
          console.log('列表', data.products)
          this.data = newList
        }
        this.tableLoading = false
      },
      closeAdd (e) {
        if (e) {
          this.getAnchorList()
        }
      },
      emptsearch () {
        Object.assign(
          this.search_queryParam,
          this.$options.data().search_queryParam
        )
        this.onSearch()
      },
      handle_look (item, type) {
        if (type == 'delete') {
          this.$confirm('是否继续此操作?', '提示', {
            confirmButtonText: '确定',
            cancelButtonText: '取消',
            type: 'warning',
          })
            .then(async () => {
              let params = {
                creator: this.useriInfo.username,
              }
              let data = await deleteGuild(params, item.id)
              if (data.code == 200) {
                this.$baseMessage('操作成功', 'success')
                setTimeout(() => {
                  this.getAnchorList()
                }, 500)
              }
            })
            .catch(() => {})

          return
        }
        this.$refs.addDrama.applynewadd(item, type)
      },

      selectionChange (selection) {
        this.seltTableData = selection
      },

      onSearch () {
        this.pagination.page = 1
        if (this.searchType) {
          this.search_queryParam[this.searchType] = this.searchText
        }
        this.getAnchorList()
      },
      // 排序 order是降序或者升序 prop是字段
      sortChange ({ order, prop }) {
        this.sort.order_type = {
          ascending: 'asc',
          descending: 'desc',
        }[order]
        this.sort.order_key = prop
        this.pagination.page = 1
        this.getAnchorList()
      },
    },
  }
</script>
<style lang="scss" scoped>
  @media screen and (max-width: 768px) {
    .marb {
      margin-top: 10px;
    }
    .tab_box {
      width: 90vw;
    }
  }
  .df {
    display: flex;
    align-items: center;
  }
  .edit-box {
    display: flex;
    align-items: center;
    justify-content: center;
  }
  .page-footer {
    position: sticky;
    bottom: 0;
    padding: 0 14px 14px;
    background-color: #fff;
    z-index: 10;
  }

  p {
    margin-bottom: 0;
  }

  .contract-tip-box {
    width: 150px;
    word-break: break-all;

    > p {
      margin-bottom: 4px;
      font-size: 12px;
    }
  }
  .account-user-box {
    display: flex;
    justify-content: space-between;
    word-break: break-all;
    background-color: #fff;
    padding: 14px 10px;
    border-radius: 10px;
    overflow: hidden;

    .head_img_box {
      position: relative;
      width: 40px;
      height: 40px;
      overflow: hidden;

      .head_img {
        width: 100%;
        height: 100%;
        border-radius: 40px;
      }

      .platform_path {
        position: absolute;
        bottom: -6px;
        right: 0;
        width: 14px;
      }
    }

    .user-text {
      margin-left: 10px;
      flex: 1;

      p {
        font-size: 12px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333333;
        line-height: 17px;

        display: flex;
        justify-content: space-between;
        margin-bottom: 6px;
      }

      .anchor_name {
        font-size: 14px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #2a304d;
        line-height: 20px;
      }

      .anchor_id {
        font-size: 12px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #8895a4;
        line-height: 17px;
        margin-bottom: 8px;
      }
    }
  }

  .acc_msg {
    display: flex;

    .account-table-box {
      display: grid;
      grid-template-columns: 1fr 1fr;
      grid-gap: 10px;
      grid-row: 10px;

      .account-box {
        display: flex;
        align-items: center;
        justify-content: center;
        width: 100px;

        .account-item {
          color: #3f8cff;
          font-size: 14px;
          padding: 2px 12px;
          line-height: 20px;
          white-space: nowrap;
          display: inline-block;
          width: 100%;
          overflow: hidden;
          text-overflow: ellipsis;

          background: #f1f7ff;
          border-radius: 2px;
          border: 1px solid #3a90ff;
          font-family: PingFangSC-Regular, PingFang SC;
          font-weight: 400;
        }
      }
    }
  }

  .artist-data {
    padding: 10px 10px 0;
    min-height: 100%;
    position: relative;
    display: flex;
    flex-direction: column;

    ::v-deep.ant-spin-nested-loading {
      background-color: #fff;
      flex: 1;
    }

    p {
      margin-bottom: 0;
    }

    .sreach-box {
      display: flex;
      align-items: center;
      justify-content: space-between;
      background: white;
      border-radius: 5px;
      margin-bottom: 20px;
      .sreach-right-box {
        display: flex;
        align-items: center;
        position: relative;
      }
      @media screen and (max-width: 768px) {
        justify-content: flex-start;
      }

      .line {
        background: #dfdfe1;
        width: 1px;
        height: 30px;
        display: inline-block;
      }

      > p {
        font-size: 14px;
        color: #333333;
      }
    }

    .screen-box {
      background-color: white;
      padding: 20px 15px 0px 15px;
      display: flex;
      align-items: flex-end;
      justify-content: space-between;

      .screen-left-box {
        flex: 1;
      }

      .item {
        display: flex;
        align-items: flex-start;
        padding-bottom: 16px;

        &:last-child {
          padding-bottom: 0px;
        }

        .tag-box {
          display: flex;
          align-items: center;
          flex-wrap: wrap;

          .screen-tag {
            cursor: pointer;
            line-height: 22px;
            padding: 0 9px;
            margin-right: 10px;
            color: #333333;
            border-radius: 2px;
            margin-bottom: 4px;

            font-size: 12px;
            font-family: PingFangSC-Medium, PingFang SC;
            font-weight: 500;

            &:hover {
              background-color: #deeafe;
              color: #333333;
            }
          }

          .screen-tag-blue {
            line-height: 17px;
            padding: 2px 9px;
            margin-right: 10px;
            color: #3f8cff;
            border: 1px solid #3f8cff;
            font-size: 14px;
            border-radius: 2px;
            display: flex;
            background-color: #f1f7ff;
            align-items: center;
            margin-bottom: 5px;
            .delete-icon {
              cursor: pointer;
              width: 11px;
              height: 11px;
              border-radius: 50%;
              background: #72b1f0;
              text-align: center;
              line-height: 9px;
              font-size: 10px;
              color: #fff;
              transform: scale(0.9);
              margin-left: 5px;

              &:hover {
                background: #2292ec;
                color: #fff;
              }
            }
          }

          .add-economy {
            cursor: pointer;
            line-height: 17px;
            padding: 2px 9px;
            margin-right: 30px;
            color: #3f8cff;
            border: 1px dashed #3f8cff;
            font-size: 14px;
            border-radius: 2px;
            display: flex;
            align-items: center;
            font-weight: bold;
            margin-bottom: 5px;
            &:hover {
              background-color: #f1f7ff;
            }
          }

          .screen-tag-active {
            background: #3a90ff !important;
            color: #fff !important;
          }
        }
      }

      .item-name {
        min-width: 80px;
        font-size: 14px;
        font-family: PingFangSC-Medium, PingFang SC;
        font-weight: 500;
        color: #333333;
        line-height: 20px;
      }

      .more-screen-box {
        cursor: pointer;
        display: flex;
        align-items: center;
        justify-content: flex-end;
        color: #3a90ff;
        font-size: 14px;
        margin-left: 10px;

        img {
          width: 20px;
          height: 20px;
          margin-right: 3px;
        }
      }
    }

    .artist-table {
      ::v-deep.el-checkbox .el-checkbox__inner {
        border-radius: 4px;
      }

      ::v-deep.el-table-column--selection .cell {
        padding-left: 14px;
      }
    }

    .footer-edit-btns {
      float: left;
      padding: 14px 0;
      display: flex;

      & > * {
        margin-right: 10px;
      }
    }

    ::v-deep.table-card {
      margin-top: 0;
      border: none;
      border-radius: 0;
    }
  }

  .right-search-body {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
  }

  .upload-list-inline ::v-deep .ant-upload-list-item {
    float: left;
    width: 200px;
    margin-right: 8px;
  }

  .upload-list-inline ::v-deep .ant-upload-animate-enter {
    animation-name: uploadAnimateInlineIn;
  }

  .upload-list-inline ::v-deep .ant-upload-animate-leave {
    animation-name: uploadAnimateInlineOut;
  }

  .ywk ::v-deep .ant-upload-list {
    display: none !important;
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    color: rgba(0, 0, 0, 0.65);
    font-size: 14px;
    font-variant: tabular-nums;
    line-height: 1.5;
    list-style: none;
    font-feature-settings: 'tnum';
    zoom: 1;
  }

  .ywk1 ::v-deep .el-input__inner {
    -webkit-appearance: none;
    background-color: #fff;
    background-image: none;
    border-radius: 4px;
    border: 1px solid #d9d9d9;
    box-sizing: border-box;
    color: #333;
    display: inline-block;
    font-size: inherit;
    height: 30px;
    line-height: 40px;
    outline: 0;
    padding: 0 15px;
    transition: border-color 0.2s cubic-bezier(0.645, 0.045, 0.355, 1);
    width: 100%;
  }

  .ywk {
    width: 370px;
  }

  .ywk ::v-deep .el-form-item__label {
    width: 130px !important;
  }

  /* .el-range__icon {
    display: none;
  } */
  /* .ywk  ::v-deep .el-input--prefix .el-input__inner {
    padding-left: 15px;
}
 .ywk2  ::v-deep .el-input--prefix .el-input__inner {
    padding-left: 15px;
} */
  /* .ywk ::v-deep.el-input__prefix, .el-input__suffix {
    top: 0;
    height: 100%;
    color: #C0C4CC;
    text-align: right;
    right: 0px !important
}
.ywk2 ::v-deep.el-input__prefix, .el-input__suffix {
    position: absolute !important;
    top: -1;
    height: 100%;
    color: #C0C4CC;
    text-align: right;
    right: 0px !important
} */
  // .add_btn {
  //   margin-bottom: 10px;
  //   background: #6bd9ba;
  //   border: none;
  // }
  // .add_btn:hover {
  //   background: #20ae71;
  // }
  /* .visab_hidden{
    position: fixed;
    z-index: -999;
} */
</style>

<style lang="scss">
  .account-table-popover {
    background-color: #fff;
    padding: 0 !important;
  }
</style>
